#include "StdAfx.h"
#include "FMDBColumn.h"
#include <stdlib.h>
#include <memory.h>

FMDBColumn::FMDBColumn(void)
{
	m_ColId=-1;	//position in a record 1-base;0 means global RowID
	m_Storage=NULL;	//storage
	m_pInd=NULL;
	m_OraType=0;
}

FMDBColumn::FMDBColumn( int ColumnId,int Size,ub2 OraType )
{
	m_ColId=ColumnId;
	m_OraType=OraType;
	m_Storage=NULL;	//storage
	m_pInd=NULL;

	SetStorageBySize(Size);
}

FMDBColumn::~FMDBColumn(void)
{
	if (m_Storage)
	{
		free(m_Storage);
	}
	if (m_pInd)
	{
		free(m_pInd);
	}
}

FMDBIOVColumn::FMDBIOVColumn( int ColumnId,int ArraySize,int DataSize,ub2 OraType )
{
	m_ColId=ColumnId;
	m_ArraySize=ArraySize;
	m_DataSize=DataSize;
	m_OraType=OraType;
	m_pInd=NULL;
	SetStorage(ArraySize,DataSize);
}

void FMDBIOVColumn::SetStorage( int ArraySize,int DataSize )
{
	//note:user should call remove storage before recreate storage.
	m_ArraySize=ArraySize;
	m_DataSize=DataSize;

	m_OCIIOV=new OCIIOV[m_ArraySize];
	for (int i =0 ;i<m_ArraySize;i++)
	{
		m_OCIIOV[i].bfl=m_DataSize;
		m_OCIIOV[i].bfp=malloc(m_DataSize);
		memset(m_OCIIOV[i].bfp,0,m_OCIIOV[i].bfl);
	}
	m_pInd=(sb2*)malloc(m_ArraySize*sizeof(sb2));
}

void FMDBIOVColumn::RemoveStorage()
{
	if (m_OCIIOV)
	{
		for (int i =0;i<m_ArraySize;i++)
		{
			free (m_OCIIOV[i].bfp);
		}
		delete (m_OCIIOV);
	}
	if (m_pInd)
	{
		free(m_pInd);
	}
}

FMDBIOVColumn::~FMDBIOVColumn( void )
{
	RemoveStorage();
}

void FMDBIOVColumn::ResetStorage()
{
	for (int i =0 ;i<m_ArraySize;i++)
	{
		memset(m_OCIIOV[i].bfp,0,m_OCIIOV[i].bfl);
	}
}

